/**
 * Author: w景洋.
 * Time: 2016/7/6 0006
 */
angular.module('service.serviceClass', [
    "ngResource",
    "ngStorage"
])

    //获取商店列表
    .service('CgzrController',['$resource',function($resource) {

        var cgzrService = $resource(infopub_baseurl+'store');
        this.getCgzrList = function(){
            return cgzrService.query();
        }
        //获取分页页数
        var cgzrPaging = $resource(infopub_baseurl+'store/bystate/count/0?num=10');
        this.getPagingNum = function(){
            return cgzrPaging.get();
        }
        //根据页数获取列表
        var pagingService = $resource(infopub_baseurl+'store/bystate/0?num=10');
        this.getPagingList = function(sNum){
            return pagingService.query({n:sNum});
        }

        //根据搜索条件获取列表
        var pagingSerachService = $resource(infopub_baseurl+'store/bysearch/0?num=10000&n=1');
        this.getPagingSearchList = function(searchname,name,minnum,maxnum){
            if(searchname=='')
            {
                searchname=null;
            }
            if(minnum=='')
            {
                minnum=null;
            }
            if(maxnum=='')
            {
                maxnum=null;
            }
            if(name=='')
            {
                name=null;
            }
            return pagingSerachService.query({searchname:searchname,name:name,
                minnum:minnum,maxnum:maxnum});
        }

    }])
    //提交要转让餐馆的信息
    .service('RestaService',['$resource',function($resource){
        var restaService = $resource(infopub_baseurl+'store');
        this.putRestaInfo = function(resta, success_func, error_func){
            restaService.save(resta).$promise.then(function(data){
                if(success_func){
                    success_func();
                }
            },function(error){
                if(error_func){
                    error_func(error);
                }
            });
        }
    }])

    //获取具体餐馆的信息
    .service('ResinfoService',['$resource',function($resource){
        this.getResinfoList = function(sId){
            var resinfoService = $resource(infopub_baseurl+'store/:storeid');
            return resinfoService.get({storeid:sId});
        }
    }])

    //上传文件
    .service('fileUpload', ['$http','$q' ,function ($http,$q) {
        var uploadUrl="http://120.55.194.39:8183/mealplan/picupload"
        this.uploadFileToUrl = function(file){
            var fd = new FormData();
            fd.append('file', file);
            var deferred = $q.defer();
            $http({
                method: "POST",
                url: uploadUrl,
                data: fd,
                headers: {'Content-Type': undefined},
                transformRequest: angular.identity
            }).success(function(data,status,headers,config){
                deferred.resolve(data);
            }).error(function(data,status,headers,config){
                deferred.reject(data);
            });
            return deferred.promise;
        }
    }])

    //获取转让中设备的信息
    .service('SbzrService',['$resource',function($resource){
        var SbzrService = $resource(infopub_baseurl+'equipment');
        this.getSbzrList = function(){
            return SbzrService.query();
        }
        //根据搜索条件获取列表
        var pagingSerachService = $resource(infopub_baseurl+'equipment/bysearch/0?num=10000&n=1');
        this.getPagingSearchList = function(name){
            if(name=='')
            {
                name=null;
            }
            return pagingSerachService.query({name:name});
        }
    }])
    //提交要转让设备的信息
    .service('DevtransService',['$resource',function($resource){
        var devtransService = $resource(infopub_baseurl+'equipment');
        this.putDevtransInfo = function(dev, success_func, error_func){
            devtransService.save(dev).$promise.then(function(data){
                if(success_func){
                    success_func();
                }
            },function(error){
                if(error_func){
                    error_func(error);
                }
            });
        }
        /*this.putDevtransInfo = function(dev, success_func, error_func){
         return devtransServic.save({},dev,success_func,error_func)
         }*/
    }])

    //获取具体设备的信息
    .service('DevinfoService',['$resource',function($resource){
        var devinfoService = $resource(infopub_baseurl+'equipment/:equipmentid');
        this.getDevinfoList = function(dId){
            return devinfoService.get({equipmentid:dId});
        }
    }])


    //获取人才招聘信息
    .service('RczpService',['$resource',function($resource){
        var rczpService = $resource(infopub_baseurl+'offer');
        this.getRczpList = function(){
            return rczpService.query();
        }
        var pagingSerachService = $resource(infopub_baseurl+'offer/bysearch/0?num=10000&n=1');
        this.getPagingSearchList = function(searchname,name,minnum,maxnum){
            if(searchname=='')
            {
                searchname=null;
            }
            if(minnum=='')
            {
                minnum=null;
            }
            if(maxnum=='')
            {
                maxnum=null;
            }
            if(name=='')
            {
                name=null;
            }
            return pagingSerachService.query({searchname:searchname,name:name,
                minnum:minnum,maxnum:maxnum});
        }
    }])
    //提交我要招聘信息
    .service('WyzpService',['$resource',function($resource){
        var wyzpService = $resource(infopub_baseurl+'offer');
        this.putZpInfo = function(zpinfo, success_func, error_func){
            wyzpService.save(zpinfo).$promise.then(function(data){
                if(success_func){
                    success_func();
                }
            },function(error){
                if(error_func){
                    error_func(error);
                }
            });
        }
    }])

    //提交我要应聘信息
    .service('WyypService',['$resource',function($resource){
        var wyypService = $resource(infopub_baseurl+'apply');
        this.putYpInfo = function(ypinfo, success_func, error_func){
            wyypService.save(ypinfo).$promise.then(function(data){
                if(success_func){
                    success_func();
                }
            },function(error){
                if(error_func){
                    error_func(error);
                }
            });
        }
    }])

    //人才招聘具体商家信息
    .service('RczpsjService',['$resource',function($resource){
        var rczpsjService = $resource(infopub_baseurl+'offer/:offerid');
        this.getRczpsjList = function(oId){
            return rczpsjService.get({offerid:oId});
        }
    }])

;